package com.sykj.controller;
import com.sykj.service.CommonService;
import com.sykj.utils.ResponseResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Description: 公共模块控制中心
 * @Author: jiangpengcheng
 * @Date: 2020/7/15
 */
@RestController
@RequestMapping("api/demo/common")
public class CommonController {

    private static final Logger logger = LoggerFactory.getLogger(com.sykj.controller.CommonController.class);

    @Autowired
    private CommonService commonService;


    /**
     * 上传文件至阿里云 oss
     *
     * @param file
     * @param
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/upload/oss", method = {RequestMethod.POST}, produces = {MediaType.APPLICATION_JSON_VALUE})
    public ResponseResult uploadOSS(@RequestParam(value = "file") MultipartFile file) throws Exception {
        ResponseResult responseResult = commonService.uploadOSS(file);

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
        return responseResult;
    }

    /**
     * 将阿里云的文件删除
     * @param objectName
     * @return
     */
   @RequestMapping("/delete/oss")
    public ResponseResult deltetOss(String objectName){
       System.out.println(objectName+"-------------------------------");
       ResponseResult delete = commonService.delete(objectName);
       return delete;
   }

}
